package com.szmg.wishwalls.action;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.szmg.wishwalls.dto.ProductionDto;
import com.szmg.wishwalls.dto.VoteSortDto;
import com.szmg.wishwalls.model.Production;
import com.szmg.wishwalls.model.WishOrder;
import com.szmg.wishwalls.service.ProductionService;
import com.szmg.wishwalls.service.WishOrderService;

@Controller("productionAction")
public class ProductionAction {
	private static final Logger log = LoggerFactory.getLogger(ProductionAction.class);
	
	@Resource(name="productionService")
	private ProductionService productionService;
	
	@Resource(name="wishOrderService")
	private WishOrderService wishOrderService;
	
	@RequestMapping(value="/json/wishwall/production_queryProductionByProgramCode",method=RequestMethod.GET)
    @ResponseBody
	public List<Production> queryProductionByProgramCode(String programCode){
		List<Production> productions = Collections.emptyList();
		try{
			productions = productionService.queryProductionByProgramCode(programCode);
		}catch(Exception e){
			log.error("ProductionAction queryProductionByProgramCode error!", e);
		}
		return productions;
	}
	
	@RequestMapping(value="/json/wishwall/production_queryProductionByMenuId",method=RequestMethod.GET)
    @ResponseBody
	public List<Production> queryProductionByMenuId(String programCode,String menuId){
		List<Production> productions = Collections.emptyList();
		try{
			productions = productionService.queryProductionByMenuId(programCode, menuId);
		}catch(Exception e){
			log.error("ProductionAction queryProductionByMenuId error!", e);
		}
		return productions;
	}
	
	@RequestMapping(value="/json/wishwall/production_queryProductionByWishOrderId",method=RequestMethod.GET)
    @ResponseBody
	public List<Production> queryProductionByWishOrderId(String wishOrderId){
		List<Production> productions = Collections.emptyList();
		try{
			productions = productionService.queryProductionByWishOrderId(wishOrderId);
		}catch(Exception e){
			log.error("ProductionAction queryProductionByWishOrderId error!", e);
		}
		return productions;
	}
	
	@RequestMapping(value="/json/wishwall/production_queryProductionById",method=RequestMethod.GET)
    @ResponseBody
	public ProductionDto queryProductionById(String productionId,String wishOrderId){
		ProductionDto dto = new ProductionDto();
		try{
			Production production = productionService.queryProductionById(productionId);
			dto.setProduction(production);
			WishOrder order = wishOrderService.queryWishOrderById(wishOrderId);
			dto.setWishOrder(order);
			List<VoteSortDto> list = wishOrderService.queryWishOrderDto(order.getProgramId(),productionId,order.getWechatId());
			dto.setVoteSortDtoList(list);
		}catch(Exception e){
			log.error("ProductionAction queryProductionById error!", e);
		}
		return dto;
	}	
}
